package com.dd.cloud.user.service.educationvisit.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.common.exception.ZekeException;
import com.dd.cloud.user.entity.educationvisit.PatientEducationVisit;
import com.dd.cloud.user.entity.educationvisit.PatientEducationVisitPushRecord;
import com.dd.cloud.user.mapper.educationvisit.PatientEducationPushRecordMapper;
import com.dd.cloud.user.service.educationvisit.IPatientEducationPushRecordService;
import com.dd.cloud.user.service.educationvisit.IPatientEducationVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 发送患教记录表 服务实现类
 * </p>
 *
 * @author czg
 * @since 2024-01-16
 */
@Service
public class PatientEducationPushRecordServiceImpl extends ServiceImpl<PatientEducationPushRecordMapper, PatientEducationVisitPushRecord> implements IPatientEducationPushRecordService {

    @Autowired
    private IPatientEducationVisitService patientEducationVisitService;

    @Override
    public void updateEducationNum(Integer pushId) {
        PatientEducationVisitPushRecord record = this.getById(pushId);
        if (record == null) {
            throw new ZekeException("记录不存在");
        }
        record.setNum(record.getNum() + 1);
        //更新文章阅读数
        Integer visitId = record.getEducationVisitId();
        PatientEducationVisit patientEducationVisit = patientEducationVisitService.getById(visitId);
        if (patientEducationVisit != null) {
            patientEducationVisitService.updatePatientEducationArticleReadCount(visitId);
        }
    }
}
